﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DepartmentManagement.DataAccess
{
    public partial class DatabaseType
    {
        /// <summary>
        /// 获取指定前缀
        /// </summary>
        /// <param name="prefixName">前缀名</param>
        /// <returns></returns>
        public PrefixType GetPrefix(string prefixName)
        {
            foreach (PrefixType pt in this.prefixesField)
            {
                if (prefixName == pt.Name)
                    return pt;
            }

            throw new IndexOutOfRangeException("There is no prefix with such name");
        }

        /// <summary>
        /// 获取指定数据表
        /// </summary>
        /// <param name="tableName">数据表名</param>
        /// <returns></returns>
        public TableType GetTable(string tableName)
        {
            foreach (TableType tt in this.tablesField)
            {
                if (tableName == tt.FullName)
                    return tt;
            }

            throw new IndexOutOfRangeException("There is no table with such name");
        }

        /// <summary>
        /// 获取指定视图
        /// </summary>
        /// <param name="viewName">视图名</param>
        /// <returns></returns>
        public ViewType GetView(string viewName)
        {
            foreach (ViewType vt in this.viewsField)
            {
                if (viewName == vt.FullName)
                    return vt;
            }

            throw new IndexOutOfRangeException("There is no view with such name");
        }
    }

    public partial class TableType
    {
        /// <summary>
        /// 获取指定字段
        /// </summary>
        /// <param name="columnName">字段名</param>
        /// <returns></returns>
        public ColumnType GetColumn(string columnName)
        {
            foreach (ColumnType ct in this.Column)
            {
                if (columnName == ct.Name)
                    return ct;
            }
            throw new IndexOutOfRangeException("There is no column with such name");
        }
    }

    public partial class ViewType
    {
        /// <summary>
        /// 获取指定字段
        /// </summary>
        /// <param name="columnName">字段名</param>
        /// <returns></returns>
        public ColumnType GetColumn(string columnName)
        {
            foreach (ColumnType ct in this.Column)
            {
                if (columnName == ct.Name)
                    return ct;
            }
            throw new IndexOutOfRangeException("There is no column with such name");
        }
    }
}
